//
//  SMACUserManager.swift
//  SmiraAiChat
//
//  Created by mumu on 2024/9/23.
//

import UIKit
enum MusicStyle:String {
    case one = "Galactic Muse"
    case two = "Space Reverie"
    case three = "Starry Solitude"
    case four = "Universe Lullaby"
}

enum HomebgStyle:String {
    case one = "Homebg_0"
    case two = "Homebg_1"
    case three = "Homebg_2"
    case four = "Homebg_3"
}

enum HomeAstroStyle:String {
    case one = "HomeAstro_0"
    case two = "HomeAstro_1"
    case three = "HomeAstro_2"
    case four = "HomeAstro_3"
}



class SMACUserManager {
    static let sharedSMAC = SMACUserManager.init()
    
    var allRandomUsers:Array<SMACUserMoadel> = Array<SMACUserMoadel>.init()
    
    var logUser:SMACUserMoadel?
    
    var musicSel:MusicStyle = .one
    var homebgSel:HomebgStyle = .one
    var homeAstroSel:HomeAstroStyle = .one
    var myplaneDiaologArray:[(isme:Bool,content:String)] = [(isme:true,content:"Me: Welcome to my rock 'n' roll bar!")]
    
    init() {
        loadAllExampleUserData()
    }
    /// 添加金币
//    func addCoinsToLogUserMAQ(_ count: Int) {
//        renweLoguserBillent((Defaults[.loguserCrape].walletCount) + count)
//    }
//    /// 更新拥有金币数
//    func renweLoguserBillent(_ count: Int) {
//       
//        if Defaults[.loguserCrape].userIDMAQ != nil {
//           Defaults[.loguserCrape].walletCount = count
//       }
//       
//       
//    }
//
//
//   //退出登录
//   func removeloguserAcountInfoMAQ() {
//       
//       Defaults[.hasbeenlogMAQ] = false
//      
//       Defaults[.loguserCrape] = MAQUserCrape.init()
//
//       asm_socket_actioner.removeAll_socketDelegate()
//   }
    
    func getRandomUserWith(count:Int,excrepID:String) -> Array<SMACUserMoadel> {
        let filteredModels = allRandomUsers.filter { $0.userID != excrepID }
        let shuffledModels = filteredModels.shuffled()
        let selectedModels = Array(shuffledModels.prefix(Int.random(in: 2...count)))
        return selectedModels
    }
    
    
    private func loadAllExampleUserData(){
        guard let path = Bundle.main.path(forResource: "RandomPersonlist", ofType: "plist") else {
               print("Plist file not found")
               return
          
        }
        
        guard let data = FileManager.default.contents(atPath: path) else {
            print("Could not load data from plist file")
            return
        }
        
        do {
              
            // 解析 plist 文件内容
            if let dictArray = try PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [[String: Any]]  {
                
                var list = Array<SMACUserMoadel>.init()
                for dict in dictArray {
                    let usermodel = SMACUserMoadel.init(userDic: dict)
                    list.append(usermodel)
                }
                allRandomUsers = list
                
            }
         
        } catch {
            print("Error parsing plist: \(error)")
        }
           
           
       }
   
    
  
}

